let init = async function() {

	const appData = {};
	//保障性用房总体情况统计
	let ret = await ajaxCall("/getOverallHouseStatistics");
	let html = '';
	let htmlfixed = '';
	for (let i = 0; i <= ret.data.length - 1; i++) {
		if (i <= ret.data.length - 2) {
			let ht = `
							<ul class="table-header">
							<li>${ret.data[i].title}</li>
							<li>${ret.data[i].houseTotalCount || 0}</li>
							<li>${ret.data[i].communityTotalCount || 0}</li>
							<li>${ret.data[i].hasRentTotalCount || 0}</li>
							<li>${ret.data[i].hasRentRate || '0%'}</li>
							</ul>
							`;
			html += ht;
			//console.log(html);
		} else {
			let htfixed = `
						<ul class="table-header">
						<li>${ret.data[i].title}</li>
						<li>${ret.data[i].houseTotalCount || 0}</li>
						<li>${ret.data[i].communityTotalCount || 0}</li>
						<li>${ret.data[i].hasRentTotalCount || 0}</li>
						<li style="width: 86px">${ret.data[i].hasRentRate || '0%'}</li>
						</ul>
						`;
			htmlfixed += htfixed
		}
	}
	$("#leftBox4Inner").html(html);
	$("#leftBox4Fixed").html(htmlfixed);

	//售价统计
	ajaxCall("/getSellingStatistics").then(ret => {
		$("#sellingStatistics1").numScroll({
			number: ret.data[0]
		})
		$("#sellingStatistics2").numScroll({
			number: ret.data[1]
		})
	});


	// 第二部分渲染
	//房源总量
	$("#houseTotalCount").numScroll({
		number: ret.data[5].houseTotalCount || 0
	})
	//已配租量
	$("#hasRentTotalCount").numScroll({
		number: ret.data[5].hasRentTotalCount || 0
	})
	//可配租量
	$("#canRentTotalCount").numScroll({
		number: (parseInt(ret.data[5].houseTotalCount) - parseInt(ret.data[5].hasRentTotalCount))
	})
	if (ret.data[5].houseTotalCount > 0) {
		let _r = (parseInt(ret.data[5].hasRentTotalCount) / parseInt(ret.data[5].houseTotalCount)) * 100;
		$("#hasRentTotalCountRate").attr("style", `width:${_r.toFixed(2)}%`);
	}
	//$("#currentServiceNumberRate").attr("style", `width:57%`);


	//分布小区个数
	$("#communityTotalCount").numScroll({
		number: ret.data[5].communityTotalCount || 0
	})
	//当前服务人数
	ajaxCall("/getCurrentServiceNumber").then(ret => {
		$("#currentServiceNumber").numScroll({
			number: ret.data || 0
		})
	});


	//房源供需分析
	ajaxCall("/getSupplyNeedAnalyse").then(ret => {
		$("#supplyNeedAnalyse1").numScroll({
			number: ret.data[0] || 0
		})
		$("#supplyNeedAnalyse2").numScroll({
			number: ret.data[1] || 0
		})
		$("#supplyNeedAnalyse3").numScroll({
			number: ret.data[2] || 0
		})
	});
	//性别统计
	ajaxCall("/getSexStatistics").then(ret => {
		$("#sexStatistics1").text(`${ret.data[0]}%`);
		$("#sexStatistics2").text(`${ret.data[1]}%`);
	})

	//年龄统计
	ajaxCall("/getAgeStatistics").then(ret => {
		$("#ageStatistics1").attr("style", `width:${ret.data[0] || 0}%`);
		$("#ageStatistics2").attr("style", `width:${ret.data[1] || 0}%`);
		$("#ageStatistics3").attr("style", `width:${ret.data[2] || 0}%`);
		$("#ageStatistics4").attr("style", `width:${ret.data[3] || 0}%`);
		$("#ageStatistics1 span").text(`${ret.data[0] || 0}`)
		$("#ageStatistics2 span").text(`${ret.data[1] || 0}`)
		$("#ageStatistics3 span").text(`${ret.data[2] || 0}`)
		$("#ageStatistics4 span").text(`${ret.data[3] || 0}`)

		let total = ret.data[0] + ret.data[1] + ret.data[2] + ret.data[3];
		if(total < 100) {
      $("#ageStatistics5").attr("style", `width:${100-total}%`);
      $("#ageStatistics5 span").text(`${100-total}`)
			$('#ageOtherBox2').show();$('#ageOtherBox1').show();
		}

	});

	//籍贯分布Top3
	ajaxCall("/getProvinceStatistics").then(ret => {
		let provinceStatisticsHtml = '';
		for (var i = 0; i < ret.data.length; i++) {
			let cln = "age-green1";
			if (i === 0) {
				cln = "age-blue1";
			}
			if (i === 1) {
				cln = "age-orange1";
			}
			let ht = `<dl>
					<dt>No.${i + 1}</dt>
					<dd class="part3-info ${cln}"><span>${ret.data[i].rate || 0}</span>%</dd>
					<dd>${ret.data[i].province || ''}</dd>
				</dl>`;
			provinceStatisticsHtml += ht;
		}
		if (ret.data.length > 0) {
			$("#provinceStatistics").html(provinceStatisticsHtml);
		}
	});


};

$(function() {
	// setInterval(() => {
	// 	init();
	// }, 0.5 * 60 * 1000)
	init();
})
